//
// Communication
//

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A', BYTE);
    delay(300);
  }
}

void respondSerial() {
  inByte = Serial.read();
  if(inByte == int('C')) {
    for(int k = 0; k < 4; k++) {
      txCommands[k] = receiveLong();
    }
    if(DEBUG) {
      // SEND DEBUG DATA
      if(txCommands[ROLL] == 123456) { 
        sendLong(1337); 
      } else { 
        sendLong(txCommands[ROLL]); 
      }
      // SEND DEBUG DATA END
    } else {
      Serial.print(loopRate, BYTE);
    }
    Serial.flush();
  }
}

//************ Transmit functions ************//
void sendLong(long data) {
  outBuffer.asLong = data;
  Serial.print(outBuffer.b[0], BYTE);
  Serial.print(outBuffer.b[1], BYTE);
  Serial.print(outBuffer.b[2], BYTE);
  Serial.print(outBuffer.b[3], BYTE);
}

//************ Receive functions ************//
long receiveLong() {
  for(int i = 3; i >= 0; i--) {
    inByte = Serial.read();
    inBuffer.b[i] = byte(inByte);
  }
  return inBuffer.asLong;
}
